package logger

import (
	"fmt"
	format "github.com/antonfisher/nested-logrus-formatter"
	log "github.com/sirupsen/logrus"
	"os"
	"path"
	"runtime"
	"strings"
	"time"
)

var Log *log.Logger

func init() {
	Log = New()
}

func New() *log.Logger {
	Logger := log.New()
	Logger.SetOutput(os.Stdout)
	Logger.SetFormatter(&format.Formatter{
		TimestampFormat: time.RFC3339,
		ShowFullLevel:   true,
		CallerFirst:     true,
		HideKeys:        false,
		CustomCallerFormatter: func(f *runtime.Frame) string {
			s := strings.Split(f.Function, ".")
			funcName := s[len(s)-1]
			if "func1" == funcName {
				funcName = s[len(s)-2]
			}
			return fmt.Sprintf(" [%s:%d][%s]", path.Base(f.File), f.Line, funcName)
		},
	})
	Logger.SetReportCaller(true)
	return Logger
}
